/**
 * File: BulkVelvetProcessor.java
 * Created by: mhaimel
 * Created on: 23 Jul 2009
 * CVS:  $Id: BulkVelvetProcessor.java,v 1.2 2009/10/09 15:12:39 mhaimel Exp $
 */
package uk.ac.ebi.curtain.processor.velvet.impl;

import org.apache.commons.lang.NotImplementedException;

import uk.ac.ebi.curtain.controller.velvet.VelvetInputBean;
import uk.ac.ebi.curtain.controller.velvet.VelvetOutputBean;
import uk.ac.ebi.curtain.processor.AbstractQueueProcessor;

/**
 * @author mhaimel
 *
 */
public class BulkVelvetProcessor extends AbstractQueueProcessor<VelvetInputBean, VelvetOutputBean> {

	@Override
	protected VelvetOutputBean buildReturnObject() {
		return null;
	}
	
	@Override
	public void process() {
		int cnt = 0;
		int res = 0;
		getLog().debug("Start velvet Bulk processing of the queue ...");
		VelvetProcessor prc = buildprocessor();
		try {
			while(true){
				if(isForceShutdown()){
					getLog().warn("FORCE shutdown!");
					break;
				}
				prc.reset();
				VelvetInputBean bean = takeInput();
				if(null != bean){
					++cnt;
					prc.setInput(bean);
					prc.process();
					VelvetOutputBean ret = prc.buildReturnObject();
					if(null != ret){
						++res;
						submitOutput(ret);
					}
				} else if(getInputQueue().isShutdown()) {
					getLog().debug("Queue finished!!");
					break;
				}
			}
		} catch (InterruptedException e) {
			getLog().warn("Interupted!!!",e);
			Thread.currentThread().interrupt();
		}
		getLog().debug("Finished velvet Bulk of " + cnt + " buckets with outputs:" + res);
	}

	protected VelvetProcessor buildprocessor() {
		return getContext().getInjector().getInstance(VelvetProcessor.class);
	}

	@Override
	protected VelvetOutputBean doProcess(VelvetInputBean input) {
		throw new NotImplementedException();
	}
	
}
